<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    let obj = {
      uname: '佩奇',
      age: 18,
      msg: [123, 34, 78],
      family: {
        brother: '乔治',
        mother: '老佩奇'
      },
    }
    const o = {}
    function deepClone(newObj, oldObj) {
      for (let k in oldObj) {
        if (oldObj[k] instanceof Array) {
          newObj[k] = []
          deepClone(newObj[k], oldObj[k])
        } else if (oldObj[k] instanceof Object) {
          newObj[k] = {}
          deepClone(newObj[k], oldObj[k])
        } else {
          newObj[k] = oldObj[k]
        }
      }
      return newObj
    }
    const res = deepClone(o, obj)
    console.log(res);
  </script>
</body>

</html>